package com.blockmeta.bbs.immodule.widget;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.PopupWindow;

import com.blockmeta.bbs.immodule.R;


public class Popup_Hongbao_Result
{
	private PopupWindow m_popup;

	private View showView;

	private OnDismissListener m_Listener;

	private Context mContext;


	public Popup_Hongbao_Result(Context pContext, View pShowView, AdapterView.OnItemClickListener pOnItemClick
                               , OnDismissListener p_Listener)
	{
		this.showView = pShowView;
		this.mContext = pContext;
		this.m_Listener = p_Listener;
		View view = LayoutInflater.from(pContext).inflate(R.layout.layout_popup_qiang_hongbao, null, false);


		view.findViewById(R.id.tv_cancel).setOnClickListener(new View.OnClickListener()
		{
			@Override
			public void onClick(View view)
			{
				dismiss();
			}
		});

		m_popup = new PopupWindow();
		m_popup.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
		m_popup.setFocusable(true);
		m_popup.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
		m_popup.setContentView(view);
		m_popup.setOnDismissListener(new PopupWindow.OnDismissListener()
		{
			@Override
			public void onDismiss()
			{
				if (null != m_Listener)
				{
					m_Listener.onDismissListener();
				}
			}
		});
	}

	public void dismiss()
	{
		if (null != m_popup && m_popup.isShowing())
		{
			m_popup.dismiss();
		}
	}

	public void show()
	{
		if (null != m_popup)
		{
			m_popup.showAtLocation(showView, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
		}
	}

	public interface OnDismissListener
	{
		void onDismissListener();
	}

}
